package com.indusfo.spc.controller;

import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.exception.GlobalException;
import com.indusfo.spc.pojo.RepairWork;
import com.indusfo.spc.service.RepairWorkService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 维修作业控制层
 */
@Controller
@RequestMapping("/service/repairWork")
public class RepairWorkController {

    @Autowired
    private RepairWorkService repairWorkService;

    /**
     * 查询
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/queryRepairWork")
    @SystemControllerLog(description="查询")
    @ResponseBody
    public JSONObject queryRepairWork(RepairWork repairWork,String startDate,String endDate) {
        JSONObject json = repairWorkService.selectRepairWork(repairWork,startDate,endDate);
        return json;
    }

    /**
     * 新增
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/insertRepairWork")
    @SystemControllerLog(description="新增")
    @ResponseBody
    public JSONObject insertRepairWork(RepairWork repairWork) {
        JSONObject json = repairWorkService.insertRepairWork(repairWork);
        return json;
    }

    /**
     * 修改
     * @return
     */
    @RequestMapping(value = "/updateRepairWork")
    @SystemControllerLog(description="修改")
    @ResponseBody
    public JSONObject updateRepairWork(RepairWork repairWork){
        JSONObject json=repairWorkService.updateRepairWork(repairWork);
        return json;
    }

    /**
     * 启用/停用
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/definedRepairWork")
    @SystemControllerLog(description="启用/停用")
    @ResponseBody
    public JSONObject definedRepairWork(Long[] repairWorkIds,Integer[] auditStates, Integer dataState) {
        JSONObject json = repairWorkService.definedRepairWork(repairWorkIds,auditStates, dataState);
        return json;
    }

    /**
     * 删除
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/deleteRepairWork")
    @SystemControllerLog(description="删除")
    @ResponseBody
    public JSONObject deleteRepairWork(Long[] repairWorkIds,Integer[] auditStates, Integer dataState) {
        dataState = 2;
        JSONObject json = repairWorkService.definedRepairWork(repairWorkIds,auditStates, dataState);
        return json;
    }

    /**
     * 审核/完结
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/auditRepairWork")
    @SystemControllerLog(description="审核/完结")
    @ResponseBody
    public JSONObject auditRepairWork(Long[] repairWorkIds, Integer[] auditStates, Integer auditState) {
        try{
            JSONObject json = repairWorkService.auditRepairWork(repairWorkIds, auditStates ,auditState);
            return json;
        } catch ( GlobalException e) {
            e.printStackTrace();
            return JSONObject.build(403, e.getMessage());
        }
    }

}
